#include"RingQueue.hpp"
#include<unistd.h>
#include<time.h>
#include"Task.hpp"
void* Product(void* arg)
{
  RingQueue<Task>* rq = static_cast<RingQueue<Task>*>(arg); 
  while(1)
  {
    const char* str = "+-*/%";
    int x = rand() % 20;
    int y = rand() % 10;
    char op = str[rand() % 5];
    cout << "发布任务:" << x <<" " << op <<" " << y <<" " << "?" << endl; 
    Task task(x,y,op);
    rq->push(task); 
  }
}


void* Consumer(void* arg)
{
  RingQueue<Task>* rq = static_cast<RingQueue<Task>*>(arg); 
  while(1)
  {
    sleep(2);
    Task t;
    rq->pop(&t);
    t();
  }
}
int main()
{
  srand((size_t)time(nullptr));
  RingQueue<Task> rq;
  pthread_t pro,con;
  pthread_create(&pro,nullptr,Product,(void*)&rq);
  pthread_create(&con,nullptr,Consumer,(void*)&rq);

  pthread_join(pro,nullptr);
  pthread_join(con,nullptr);
  return 0;
}
